import { ConnectedRouter } from "connected-react-router";
import { Route, Switch } from "react-router";
import { history } from "../redux/configStore";
import loadable from "../utils/loadable";
import PermissionRouter from "../utils/PermissionRouter";
import NotFound from "@/containers/404/Index";

const Login = loadable(() => import("../containers/Login/Login"));

const DashBoard = loadable(() => import("../containers/Login/DashBoard"));

const ChangePassword = loadable(
  () => import("../containers/Login/ChangePassword/ChangePassword")
);

const HomePage = loadable(
  () => import("../containers/Homepage/views/HomePage")
);

const NoPermission = loadable(() => import("../components/Error/NoPermission"));

const NoLogin = loadable(() => import("../components/Error/NoLogin"));

const Home = loadable(() => import("@/containers/Home/Index"));

const Error = loadable(() => import("@/containers/error/error"));

const QrcodeList = loadable(
  () =>
    import(
      "@/containers/EntranceManage/views/StudentManage/StudentInformationManage/QrcodeList"
    )
);

const Routes = () => {
  return (
    <ConnectedRouter history={history}>
      <Switch>
        <Route path="/qrcodeList/:token/:value/:label" component={QrcodeList} />
        {/* 根页面 */}
        <Route path="/" exact component={DashBoard} />
        {/* 登录页面 */}
        <Route path="/login" component={Login} />
        {/* 修改密码的页面 */}
        <Route path="/changePassword" component={ChangePassword} />

        <Route path={"/home/index"} component={Home} />
        {/* 登录进去的主页 */}
        <PermissionRouter path="/homepage" component={HomePage} />

        {/* 没有权限访问 */}
        <Route path="/nopermission" component={NoPermission} />
        {/* 登录过期 */}
        <Route path="/nologin" component={NoLogin} exact />

        <Route path="/error" component={Error} exact />

        <Route path={"*"} component={NotFound} exact />
      </Switch>
    </ConnectedRouter>
  );
};

export default Routes;
